﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PaiBanDaPing
{
    public class ScreenHelper
    {
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowPos", SetLastError = true)]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

        /// <summary>
        /// 指定屏幕分配指定窗体
        /// </summary>
        /// <param name="screen">屏幕</param>
        /// <param name="win">窗体</param>
        /// <returns>操作成功</returns>
        public static bool ShowToScreen(System.Windows.Forms.Screen screen, IntPtr wpfHwnd)
        {
            try
            {
                bool show = SetWindowPos(wpfHwnd, (IntPtr)(0), screen.Bounds.Location.X - 5, screen.Bounds.Location.Y - 8, screen.Bounds.Width + 10, screen.Bounds.Height + 15, 0x0040);
                if (show)
                {
                    return true;
                }
            }
            catch (Exception e)
            {
                //LogHelper.Error(typeof(Utils), e.Message);
            }
            return false;
        }
    }
}
